package coms.example.demo.dao;

import coms.example.demo.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

@Mapper
@Repository
public interface UserDao {

          User findUserByCity(String city);
          int insertUser(HashMap<String, Object> map);

     /**
      * 查寻所有用户
      * @return
      */
     @Select("SELECT * FROM `user`")
     List<User> getUserList();


     /**
      * 添加用户
      */

     @Insert("insert into user( `username`, `password`, `birthday`)"
          + "values (#{username}, #{password}, #{birthday})")
     void save(User user);
     /**
      * 编辑用户
      */
     @Update("<script>"+
          "update user " +
          "<set>" +
          "<if test=\"username != null\">`username` = #{username}, </if>" +
          "<if test=\"password != null\">`password` = #{password}, </if>" +
          "<if test=\"id != null\">`id` = #{id}, </if>" +
          "<if test=\"birthday != null\">`birthday` = #{birthday}, </if>" +
          "</set>" +
          "where id = #{id}"+
          "</script>")
      int edit(User user);
     /**
      * 删除用户
      */
     @Delete("delete from user where id = #{id}")
     int delete(Integer id);

     /**
      * 查询一条数据
      * 通过id
      */
     @Select("select * from user where id = #{id}")
     User getUserByid(Integer id);
}
